﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using PowerCreator.LMS.Common.Script;

public partial class Theme_3_AddRefer :PowerCreator.LMS.Web.Base.WebBasePage
{
    PowerCreator.LMS.Web.Refer.Refer opRefer = new PowerCreator.LMS.Web.Refer.Refer();
    protected PowerCreator.LMS.Web.Config.WebConfig config = new PowerCreator.LMS.Web.Config.WebConfig();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            InitPage();
            this.Title = config.GetLanagerValueByKey("theme_Refer_AddRefer", PowerCreator.LMS.Language.LanagetItemType.Page);
        }
    }
    protected override void InitPage()
    {
        btnSave.Text = GetLanageValueByKey("btn_EditResourceInfo_Save", PowerCreator.LMS.Language.LanagetItemType.Page);
        btnReset.Text = GetLanageValueByKey("btn_EditResourceInfo_Reset", PowerCreator.LMS.Language.LanagetItemType.Page);
        base.InitPage();
    }

    protected void btnReset_Click(object sender, EventArgs e)
    {
        string url = "Refer.aspx";
        PowerCreator.LMS.Common.Script.Script.RedirectURL(url);
    }
    private bool CheckPageData()
    {
        string search = string.Format("ReferTitle = '{0}'", txt_ReferTitle.Text);
        if (opRefer.Count(search) != 0)
        {
            lbl_msg_Error.Text = "<br />"+config.GetLanagerValueByKey("msg_AddRefer_Msg1", PowerCreator.LMS.Language.LanagetItemType.Page);
            return false;
        }
        return true;
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (!CheckPageData()) return;
        PowerCreator.LMS.Refer.Entity.VOTRefer voRefer = new PowerCreator.LMS.Refer.Entity.VOTRefer();
        voRefer.ReferTitle = txt_ReferTitle.Text.Trim();
        voRefer.ReferContent = txt_ReferContent.Text.Trim();
        voRefer.ReferName = txt_ReferName.Text.Trim();
        voRefer.ReferEmail = txt_ReferEmail.Text.Trim();
        voRefer.ReferTelephone = txt_ReferTelephone.Text.Trim();
        voRefer.ReferTime = DateTime.Now;


        if (opRefer.AddRefer(voRefer))
        {
            string url = "Refer.aspx";
            Script.ShowAndRedirect(this, config.GetLanagerValueByKey("theme_Theme_AddRefer_Msg1", PowerCreator.LMS.Language.LanagetItemType.Page), url);
        }
    }
}
